from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-21 14:02:34.418242
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 21, Mar, 2022
Time: 14:02:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.6066
Nobs: 601.000 HQIC: -49.0089
Log likelihood: 7219.17 FPE: 4.02142e-22
AIC: -49.2653 Det(Omega_mle): 3.46640e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350447 0.066670 5.256 0.000
L1.Burgenland 0.107673 0.040589 2.653 0.008
L1.Kärnten -0.110561 0.021230 -5.208 0.000
L1.Niederösterreich 0.193316 0.084860 2.278 0.023
L1.Oberösterreich 0.120766 0.083661 1.444 0.149
L1.Salzburg 0.258739 0.043059 6.009 0.000
L1.Steiermark 0.036708 0.056846 0.646 0.518
L1.Tirol 0.102262 0.045867 2.230 0.026
L1.Vorarlberg -0.067828 0.040492 -1.675 0.094
L1.Wien 0.015817 0.074460 0.212 0.832
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054672 0.143255 0.382 0.703
L1.Burgenland -0.037985 0.087215 -0.436 0.663
L1.Kärnten 0.041962 0.045616 0.920 0.358
L1.Niederösterreich -0.203484 0.182340 -1.116 0.264
L1.Oberösterreich 0.454721 0.179764 2.530 0.011
L1.Salzburg 0.282944 0.092522 3.058 0.002
L1.Steiermark 0.112716 0.122146 0.923 0.356
L1.Tirol 0.306176 0.098555 3.107 0.002
L1.Vorarlberg 0.026577 0.087005 0.305 0.760
L1.Wien -0.029395 0.159992 -0.184 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198666 0.034067 5.832 0.000
L1.Burgenland 0.089106 0.020740 4.296 0.000
L1.Kärnten -0.007173 0.010848 -0.661 0.508
L1.Niederösterreich 0.242086 0.043362 5.583 0.000
L1.Oberösterreich 0.159666 0.042750 3.735 0.000
L1.Salzburg 0.039976 0.022003 1.817 0.069
L1.Steiermark 0.026976 0.029047 0.929 0.353
L1.Tirol 0.081832 0.023437 3.492 0.000
L1.Vorarlberg 0.054097 0.020691 2.615 0.009
L1.Wien 0.116942 0.038048 3.074 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118758 0.034064 3.486 0.000
L1.Burgenland 0.043047 0.020738 2.076 0.038
L1.Kärnten -0.012906 0.010847 -1.190 0.234
L1.Niederösterreich 0.171794 0.043357 3.962 0.000
L1.Oberösterreich 0.335697 0.042745 7.854 0.000
L1.Salzburg 0.099800 0.022000 4.536 0.000
L1.Steiermark 0.111875 0.029044 3.852 0.000
L1.Tirol 0.089116 0.023435 3.803 0.000
L1.Vorarlberg 0.060674 0.020688 2.933 0.003
L1.Wien -0.018039 0.038043 -0.474 0.635
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126547 0.063929 1.979 0.048
L1.Burgenland -0.044443 0.038921 -1.142 0.254
L1.Kärnten -0.045325 0.020357 -2.227 0.026
L1.Niederösterreich 0.135642 0.081372 1.667 0.096
L1.Oberösterreich 0.161309 0.080222 2.011 0.044
L1.Salzburg 0.284530 0.041289 6.891 0.000
L1.Steiermark 0.058208 0.054509 1.068 0.286
L1.Tirol 0.158028 0.043982 3.593 0.000
L1.Vorarlberg 0.097468 0.038827 2.510 0.012
L1.Wien 0.071109 0.071399 0.996 0.319
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077326 0.049877 1.550 0.121
L1.Burgenland 0.025846 0.030366 0.851 0.395
L1.Kärnten 0.053262 0.015882 3.354 0.001
L1.Niederösterreich 0.190649 0.063486 3.003 0.003
L1.Oberösterreich 0.330493 0.062589 5.280 0.000
L1.Salzburg 0.034787 0.032214 1.080 0.280
L1.Steiermark 0.008205 0.042528 0.193 0.847
L1.Tirol 0.119259 0.034314 3.475 0.001
L1.Vorarlberg 0.065861 0.030293 2.174 0.030
L1.Wien 0.096340 0.055705 1.729 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174707 0.060168 2.904 0.004
L1.Burgenland 0.005925 0.036631 0.162 0.872
L1.Kärnten -0.065923 0.019159 -3.441 0.001
L1.Niederösterreich -0.107582 0.076584 -1.405 0.160
L1.Oberösterreich 0.206745 0.075502 2.738 0.006
L1.Salzburg 0.054464 0.038860 1.402 0.161
L1.Steiermark 0.247043 0.051302 4.815 0.000
L1.Tirol 0.501614 0.041394 12.118 0.000
L1.Vorarlberg 0.064302 0.036543 1.760 0.078
L1.Wien -0.078409 0.067197 -1.167 0.243
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161056 0.066747 2.413 0.016
L1.Burgenland -0.001401 0.040636 -0.034 0.972
L1.Kärnten 0.062831 0.021254 2.956 0.003
L1.Niederösterreich 0.167644 0.084959 1.973 0.048
L1.Oberösterreich -0.056713 0.083758 -0.677 0.498
L1.Salzburg 0.208105 0.043109 4.827 0.000
L1.Steiermark 0.138702 0.056912 2.437 0.015
L1.Tirol 0.056666 0.045920 1.234 0.217
L1.Vorarlberg 0.146993 0.040539 3.626 0.000
L1.Wien 0.119207 0.074546 1.599 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390062 0.039286 9.929 0.000
L1.Burgenland -0.003564 0.023918 -0.149 0.882
L1.Kärnten -0.020859 0.012510 -1.667 0.095
L1.Niederösterreich 0.202267 0.050005 4.045 0.000
L1.Oberösterreich 0.230115 0.049299 4.668 0.000
L1.Salzburg 0.036623 0.025373 1.443 0.149
L1.Steiermark -0.015630 0.033497 -0.467 0.641
L1.Tirol 0.088897 0.027028 3.289 0.001
L1.Vorarlberg 0.050902 0.023860 2.133 0.033
L1.Wien 0.044232 0.043876 1.008 0.313
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036559 0.104104 0.168223 0.137114 0.096945 0.079467 0.032120 0.208523
Kärnten 0.036559 1.000000 -0.026965 0.131044 0.048663 0.084776 0.443655 -0.066915 0.089244
Niederösterreich 0.104104 -0.026965 1.000000 0.312476 0.118752 0.272396 0.066253 0.153031 0.292059
Oberösterreich 0.168223 0.131044 0.312476 1.000000 0.212154 0.294892 0.165862 0.136211 0.238722
Salzburg 0.137114 0.048663 0.118752 0.212154 1.000000 0.122370 0.091975 0.105044 0.124030
Steiermark 0.096945 0.084776 0.272396 0.294892 0.122370 1.000000 0.133558 0.106774 0.035235
Tirol 0.079467 0.443655 0.066253 0.165862 0.091975 0.133558 1.000000 0.064138 0.150376
Vorarlberg 0.032120 -0.066915 0.153031 0.136211 0.105044 0.106774 0.064138 1.000000 -0.004234
Wien 0.208523 0.089244 0.292059 0.238722 0.124030 0.035235 0.150376 -0.004234 1.000000